package cn.elwy.rcp.ui.table.listener;

import java.util.List;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.actions.ActionGroup;

import cn.elwy.rcp.ui.table.TablePane;

public class TablePaneActionGroup extends ActionGroup {

  private ColumnViewer columnViewer;
  private TablePane tablePane;
  private List<TablePaneAction> actionList;

  public TablePaneActionGroup() {
  }

  public void makeActions() {
    actionList = tablePane.getTableInfo().getActionList();
    for (TablePaneAction action : actionList) {
      action.setTablePane(tablePane);
    }
  }

  public void fillContextMenu(IMenuManager menu) {
    IStructuredSelection selection = (IStructuredSelection) columnViewer.getSelection();
    if (selection == null) {
      return;
    }
    for (TablePaneAction action : actionList) {
      menu.add(action);
    }
  }

  public ColumnViewer getColumnViewer() {
    return columnViewer;
  }

  public void setColumnViewer(ColumnViewer columnViewer) {
    this.columnViewer = columnViewer;
  }

  public TablePane getTablePane() {
    return tablePane;
  }

  public void setTablePane(TablePane tablePane) {
    this.tablePane = tablePane;
  }

}
